/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model.acl;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Anthares
 */
public class Ressource {

    private String name;
    private List<UserType> allowed_roles;

    public Ressource(String resName) {
        this.name = resName;
        allowed_roles = new ArrayList<UserType>();
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void allow(UserType role) {
        if (!allowed_roles.contains(role)) {
            allowed_roles.add(role);
        }
    }

    public boolean hasAccess(UserType role) {
        for (UserType allowedRole : allowed_roles) {
            if (role.isA(allowedRole.getType())) {
                return true;
            }
        }
        return false;
    }
}
